package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.order.TbOrder;
import com.guigu.qingcheng.service.CartFeign;
import com.guigu.qingcheng.utils.R;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class CartController {

    @Autowired
    private CartFeign cartFeign;

    @GetMapping("findCartList")
    public List<Map<String, Object>> findCartList () {
        String username = "覃仁斌";
        return cartFeign.findCartList(username);
    }

    /**
     * 添加商品到购物车
     * @param skuId 商品id
     * @param num 数量
     * @return
     */

    @GetMapping("addItem")
    public R addItem(String skuId, Integer num) {
        String username = "覃仁斌";
        cartFeign.addItem(username,skuId,num);
        return R.ok();
    }

    @GetMapping("updateChecked")
    public R updateChecked(String skuId, boolean checked) {
        String username = "覃仁斌";
        cartFeign.updateChecked(username,skuId,checked);
        return R.ok();
    }

    @GetMapping("delete")
    public R delete() {
        return cartFeign.deleteCheckedCart();
    }

    @GetMapping("preferential")
    public Map preferential() {
        return cartFeign.preferential();
    }

    @GetMapping("findNewOrderItemList")
    public List<Map<String, Object>> findNewOrderItemList() {
        return cartFeign.findNewOrderItemList();
    }

    @PostMapping("saveOrder")
    public Map<String,Object> saveOrder(@RequestBody TbOrder order ){
        return cartFeign.saveOrder(order);
    }
}
